package cn.kennylee.codehub.springboot.microtrace.condition;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.lang.NonNull;

import static cn.kennylee.codehub.springboot.microtrace.TraceProperties.TRACE_ID_CONFIG_PREFIX;

/**
 * <p> 是否启用链路追踪 </p>
 * <p>Created on 2025/5/10.</p>
 *
 * @author kennylee
 * @since 0.0.1
 */
@Slf4j
public class OnTraceEnabledCondition implements Condition {
    @Override
    public boolean matches(@NonNull ConditionContext context, @NonNull AnnotatedTypeMetadata metadata) {
        Environment env = context.getEnvironment();
        return env.getProperty(TRACE_ID_CONFIG_PREFIX + ".enabled", Boolean.class, true);
    }
}
